<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>InvariantJ - Using InvariantJ with Eclipse</title>
		<link rel="stylesheet" href="style.css" type="text/css"/>
		<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
		<meta name="author" content="Lance Walton" lang="en-uk"/>
	</head>
	<body>
		<div class="main">
			<div class="pageTitle">InvariantJ and Eclipse</div>
			<div class="contents">
				<ul>
					<li> <a href="index.html" title="InvariantJ Home">Home</a>
					</li>
				</ul>
			</div>
			<div class="sectionHeading"> <a name="eclipseBuilders">Eclipse Builders</a>
			</div>
			<p>To use InvariantJ within Eclipse, you need to set up a 'builder'. Eclipse allows you to use <a href="http://ant.apache.org/" title="Apache Ant website">
				Ant</a> tasks as builders, so no special plugin is required - the Ant <a href="index.html#compiling"
					title="How to compile and instrument your classes for invariant checking">task</a> described on the <a href="index.html#introduction"
					title="InvariantJ Home">previous page</a> provides most of the necessary functionality. The only addition required is another task that is
				dependent on the one described before and which copies the instrumented classes back to the original location. For a complete example, see <a
					href="build.xml.txt" title="Example Ant build file">build.xml</a> (you might want to avoid the dependency on the original 'instrument' target to
				eliminate unnecessary compilations, but the principle is the same regardless):</p>
			<ul class="codeBlock">
				<li>&lt;
					<span class="keyword">target</span>
					<span class="variable">name</span>="
					<span class="string">eclipseInvariants</span>"
					<span class="variable">depends</span>="
					<span class="string">init,&nbsp;instrument</span>"&gt;</li>
				<li>&nbsp;&nbsp;&lt;
					<span class="keyword">copy</span>
					<span class="variable">todir</span>="
					<span class="string">&#8230;where Eclipse is putting the compiled classes&#8230;</span>"&gt;</li>
				<li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;
					<span class="keyword">fileset</span>
					<span class="variable">dir</span>="
					<span class="string">&#8230;where the instrumented classes were written to&#8230;</span>"
					<span class="variable">includes</span>="
					<span class="string">**/*.class</span>"/&gt;</li>
				<li>&nbsp;&nbsp;&lt;/
					<span class="keyword">copy</span>&gt;</li>
				<li>&lt;/
					<span class="keyword">target</span>&gt;</li>
			</ul>
			<p>To invoke this target at the appropriate times, open the Project&nbsp;/&nbsp;Properties dialog for your project and select the 'Builders' item:</p>
			<p/><img src="eclipse/PropertiesStart.tiff" alt="Eclipse Properties dialog"/>
			
			<p>Now click the 'New' button to pop up the 'Choose configuration type' dialog and select the 'Ant Build' option:</p>
			<p/><img src="eclipse/ChooseConfigurationType.tiff" alt="Adding a new incremental builder"/>
			
			<p>Click 'OK' and the new builder properties dialog will appear. Type a name into the 'Name' field:</p>
			<p/><img src="eclipse/LaunchConfigurationMainStart.tiff" alt="Initial Launch Configuration Editor dialog"/>
			
			<p>To select the Ant build file to use, click the 'Browse Workspace...' button in the 'Buildfile' section of the 'Main' tab of the dialog:</p>
			<p/><img src="eclipse/BrowseForBuildfile.tiff" alt="Browsing for the build file"/>
			
			<p>Click 'OK' and then select the Base Directory to run the builder in; click the 'Browse Workspace...' button in the 'Base Directory' section of the 'Main' tab of
				the dialog and then choose the base directory in the 'Folder Selection' dialog:</p>
			<p/><img src="eclipse/BrowseForBaseDirectory.tiff" alt="Browsing for the Base Directory"/>
			
			<p>Click 'OK' and then select the 'Refresh' tab of the properties dialog. Check the 'Refresh resources upon completion' checkbox and choose to refresh 'Specific
				Resources':</p>
			<p/><img src="eclipse/Refresh.tiff" alt="Refreshing resources after invariant decoration"/>
			
			<p>Click the 'Specify Resources' button and select the classes directory for your project:</p>
			<p/><img src="eclipse/RefreshResources.tiff" alt="Refreshing the classes after invariant decoration"/>
			
			<p>Click the 'Finish' button and select the 'Targets' tab of the properties dialog:</p>
			<p/><img src="eclipse/Targets.tiff" alt="Properties dialog Targets tab"/>
			
			<p>Now set the 'Manual Build' and 'Auto Build' Ant targets defined in the Ant file as described above:</p>
			<p/><img src="eclipse/BuildTargets.tiff" alt="Properties dialog Targets tab"/>
			
			<p>Clicking 'OK' will now yield:</p>
			<p/><img src="eclipse/LaunchEnd.tiff" alt="Targets tab with selected build targets"/>
			
			<p>Clicking 'OK' in this dialog will cause Eclipse to return to the Builder Properties dialog:</p>
			<p/><img src="eclipse/PropertiesEnd.tiff" alt="Build properties dialog with new Ant builder"/>
			
			<p>And clicking 'OK' here should cause Ant to launch and the chosen target to execute. There will probably be some Console output when this occurs.</p>
		</div>
	</body>
</html>